package com.shixun.dds_11.controller;


import com.shixun.dds_11.context.BaseContext;
import com.shixun.dds_11.entity.DdsAddress;
import com.shixun.dds_11.result.Result;
import com.shixun.dds_11.service.IDdsAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LH
 * @since 2024-07-05
 */
@CrossOrigin
@RestController
@RequestMapping("/dds11/address")
@Api(tags = "收货地址相关接口")
@Slf4j
public class DdsAddressController {

    @Autowired
    private IDdsAddressService iDdsAddressService;





//    /**
//     * 删除单条地址信息
//     * @param id
//     * @return
//     */
//    @DeleteMapping("/delete/{id}")
//    @ApiOperation(value = "删除单条地址")
//    public Result<String> deleteOne(@PathVariable Integer id) {
//        if (iDdsAddressService.deleteOne(id) != 0) {
//            return Result.success("success");
//        }
//        return Result.error("fail");
//    }

//    /**
//     * 删除该用户所有的地址信息
//     * @param userId
//     * @return
//     */
//    @DeleteMapping("/delete-all/{userId}")
//    @ApiOperation(value = "删除该用户所有的地址信息")
//    public Result<String> deleteAll(@PathVariable Integer userId) {
//        if (iDdsAddressService.deleteAll(userId) != 0) {
//            return Result.success("success");
//        }
//        return Result.error("fail");
//    }


    /**
     * 修改地址信息
     * @param ddsAddress
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改地址信息")
    public Result<String> updateAddress(@RequestBody DdsAddress ddsAddress) {
        iDdsAddressService.update(ddsAddress);
        log.info("userId:{}", ddsAddress.getUserId());
        return Result.success();
    }

    // 查询某条具体的地址信息

    /**
     * 查询地址
     * @return
     */
    @GetMapping("/select")
    @ApiOperation(value = "查询地址")
    public Result<DdsAddress> findOne() {
        Integer userId = BaseContext.getCurrentId().intValue();
        DdsAddress ddsAddress = iDdsAddressService.findOne(userId);
        if (ddsAddress == null) return Result.error(null);
        return Result.success(ddsAddress);
    }

//    // 查询所有地址信息
//    @GetMapping("select-all/{userId}")
//    public Result<List<DdsAddress>> findAll(@PathVariable Integer userId) {
//        List<DdsAddress> ddsAddressList = iDdsAddressService.findAll(userId);
//        if (ddsAddressList == null) return Result.error(null);
//        return Result.success(ddsAddressList);
//    }

//    /**
//     * 查询所有地址
//     * @param addressPageQueryDTO
//     * @return
//     */
//    @GetMapping("/page")
//    @ApiOperation(value = "地址列表")
//    public Result<PageResult> pageQuery(AddressPageQueryDTO addressPageQueryDTO, HttpServletRequest request) {
//        HttpSession session = request.getSession();
//        DdsUser user = (DdsUser) session.getAttribute("user");
//        addressPageQueryDTO.setUserId(user.getId());
//        log.info("地址列表：{}", addressPageQueryDTO);
//        PageResult pageResult = iDdsAddressService.pageQuery(addressPageQueryDTO);
//        return Result.success(pageResult);
//    }

}
